package com.fiona.start.base;

import com.fiona.common.base.config.FionaConfig;
import com.fiona.common.base.config.RpcConfig;
import com.fiona.common.exception.RemotingException;
import com.fiona.common.extension.Extension;
import com.fiona.common.extension.ExtensionLoader;
import com.fiona.remoting.api.Transporter;
import com.fiona.start.IStart;

@Extension(order=2)
public class TransporterStart implements IStart{
	
	@Override
	public void start(Class<?> clazz) {
		//获取配置文件内容，查看是否有服务端口号配置 
		if (null != FionaConfig.getServerAddress()) {
			Transporter transporter;
			if (null != RpcConfig.getTransporter()) {
				transporter = ExtensionLoader.getExtensionLoader(Transporter.class).getExtension(RpcConfig.getTransporter());
			} else {
				transporter = ExtensionLoader.getExtensionLoader(Transporter.class).getExtension("netty");
			}
			try {
				transporter.bind(FionaConfig.getServerAddress());
			} catch (RemotingException e) {
				e.printStackTrace();
			}
		}
	}


}
